<?php
	require_once("../conexion/conexion.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="../Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />

<script src="../include_js/jquery.js" type="text/javascript"></script>
<style>
a:link {color:#0033FF;} /* Link no visitado*/
a:visited {text-decoration:none; color:#666666;} /*Link visitado*/
a:hover {color:#990000;} /*Mouse sobre el link*/
</style>
<script>
function Factura(valor,doc)
{
	
	id = document.getElementById("tbExp").rows[valor].cells[0].innerText;
	prov = document.getElementById("tbExp").rows[valor].cells[1].innerText;
	//alert(id);
	if(doc==1)
	{window.open("Contabilidad/Ventana_FacNormal.php?num="+id+"&prov="+prov,"VentanaFactura","width=700,height=400,scrollbars=yes");}
	else
	{
		if(doc==2)
		{window.open("Contabilidad/Ventana_FacExenta.php?num="+id+"&prov="+prov,"VentanaFactura","width=700,height=380,scrollbars=yes");}
		else
		{
			if(doc==3)
			{window.open("Contabilidad/Ventana_FacElectronica.php?num="+id+"&prov="+prov,"VentanaFactura","width=700,height=380,scrollbars=yes");}
		}
	}
}

function Eliminar(valor)
{
	id = document.getElementById("tbOtros").rows[valor].cells[0].innerText;
	numero = document.getElementById("tbOtros").rows[valor].cells[1].innerText;
	//alert(id+" "+numero);
	$.ajax({
					type: 'POST',
					url: 'Produccion/Eliminar_Otros.php',
					data: {id:id,numero:numero},
					success: function(data) {
						$('#eliminar').html(data);
						Direccionar();
					}
				})
}

function Direccionar()
{
	//alert('dir');
		$.ajax({
				type: 'POST',
				url: 'Produccion/carga_busqueda_decl_3.php',
				data: $('#form_Busqueda_Decl').serialize(),
				success: function(data) {
					$('#capa').html(data);
				}
			})
}
</script>
</head>

<body>
<form name="carga_busqueda_exp" id="carga_busqueda_exp" method="post">
<?php
	
	extract($_POST);
 
	$cont = 0;
	//proveedor
 	if ($cmb_Proveedor=="0")
	{
		$cmb_Proveedor="null";
		$cont++;
	}
	else
	{$cmb_Proveedor="'".$cmb_Proveedor."'";}
	
	//fecha inicio
	if ($txtFIni==""){
		$txtFIni="null";
		$cont++;
	}
	else
	{
		$FechaIni = explode("-", $txtFIni);
		$txtFIni = "$FechaIni[2]-$FechaIni[1]-$FechaIni[0]";
	}
	//fecha fin
	if ($txtFFin==""){
		$txtFFin="null";
		$cont++;
	}
	else
	{
		$FechaFin = explode("-", $txtFFin);
		$txtFFin = "$FechaFin[2]-$FechaFin[1]-$FechaFin[0]";
	}
	//factura normal
 	if ($cmb_Documento=="1")
	{
		$sql = "select
				FacNNum,
				ProvNombre,
				ANombre,
				date_format(FacNFecha,'%d/%m/%Y') as fecha,
				FacNTotal,
				FacNEstado
				
				from FacturaNormal fn
				inner join Proveedor p on
				fn.ProvRut=p.ProvRut
				inner join Area a on
				fn.ACod=a.ACod
				
				where
				(($cmb_Proveedor is NULL) or (fn.ProvRut = $cmb_Proveedor)) and
				((($txtFIni is NULL) and ($txtFFin is NULL)) or DATE(FacNFecha) BETWEEN '".$txtFIni."' and '".$txtFFin."')";
	}
	else
	{
		//factura exenta
		if($cmb_Documento=="2")
		{
			$sql = "select
				FacENum,
				ProvNombre,
				ANombre,
				date_format(FacEFecha,'%d/%m/%Y') as fecha,
				FacETotal,
				FacEEstado
				
				from FacturaExenta fe
				inner join Proveedor p on
				fe.ProvRut=p.ProvRut
				inner join Area a on
				fe.ACod=a.ACod
				
				where
				(($cmb_Proveedor is NULL) or (fe.ProvRut = $cmb_Proveedor)) and
				((($txtFIni is NULL) and ($txtFFin is NULL)) or DATE(FacEFecha) BETWEEN '".$txtFIni."' and '".$txtFFin."')";
				//echo $sql;
		}
		else
		{
			//factura electronica
			if($cmb_Documento=="3")
			{
				$sql = "select
				FacElecNum,
				ProvNombre,
				ANombre,
				date_format(FacElecFecha,'%d/%m/%Y') as fecha,
				FacElecTotal,
				FacElecEstado
				
				from FacturaElectronica fe
				inner join Proveedor p on
				fe.ProvRut=p.ProvRut
				inner join Area a on
				fe.ACod=a.ACod
				
				where
				(($cmb_Proveedor is NULL) or (fe.ProvRut = $cmb_Proveedor)) and
				((($txtFIni is NULL) and ($txtFFin is NULL)) or DATE(FacElecFecha) BETWEEN '".$txtFIni."' and '".$txtFFin."')";
				//echo $sql;
			}
		}
	}
	
	
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
			$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
			$fila = mysql_num_rows($res);
			if($fila >0)
			{?>
			<div class="cabecera2">
			<table width="100%" border="0" class="fija" cellpadding="0" cellspacing="0" id="tbExp">
			<thead class="fija">
      		  <tr class="fija">
			  	<th width="13%" class="fija">n&deg; factura</th>
				<th width="27%" class="fija">proveedor</th>
			    <th width="19%" class="fija">area</th>
				<th width="13%" class="fija">fecha</th>
			    <th width="15%" class="fija">monto $</th>
				<th width="13%" class="fija">estado</th>
			  </tr>
			 </thead>
			 <tbody class="fija">
				<tr class="fija"><td colspan="6" class="fija">&nbsp;</td></tr>
			<?php
			$aux = 2;
			while($reg = mysql_fetch_array($res))
			{
				if(($aux % 2)==0)
				{
					echo "<tr class='filaImpar' id='".$aux."'>";
					echo "<td width=\"13%\" style='text-align:center'><a href='javascript:Factura($aux,$cmb_Documento);'>".$reg[0]."</a></td>";
					echo "<td width=\"27%\" style='text-align:lefth;padding-left:5px;'>".$reg[1]."</td>";
					echo "<td width=\"19%\" style='text-align:lefth;padding-left:5px;'>".$reg[2]."</td>";
					echo "<td width=\"13%\" style='text-align:center'>".$reg[3]."</td>";
					echo "<td width=\"15%\" style='text-align:center'>".number_format($reg[4],0,',','.')."</td>";
					echo "<td width=\"13%\" style='text-align:center'>".$reg[5]."</td>";
					echo "</tr>";
				}
				else
				{
					echo "<tr class='filaPar' id='".$aux."'>";
					echo "<td width=\"13%\" style='text-align:center'><a href='javascript:Factura($aux,$cmb_Documento);'>".$reg[0]."</a></td>";
					echo "<td width=\"27%\" style='text-align:lefth;padding-left:5px;'>".$reg[1]."</td>";
					echo "<td width=\"19%\" style='text-align:lefth;padding-left:5px;'>".$reg[2]."</td>";
					echo "<td width=\"13%\" style='text-align:center'>".$reg[3]."</td>";
					echo "<td width=\"15%\" style='text-align:center'>".number_format($reg[4],0,',','.')."</td>";
					echo "<td width=\"13%\" style='text-align:center'>".$reg[5]."</td>";
					echo "</tr>";
				}
				$aux++;
			}
			?>
      </tbody>
	  </table>
	  </div>
	  <?php }
			else
			{echo "<label style='font-size:16px; color:#CC3333; font-weight:bold;'>No Existen Resultados para la B&uacute;squeda</label>";}
 ?>
<div id="eliminar"></div>
</form>
</body>
</html>
